package com.jsss.echarts.service;

import com.jsss.echarts.dao.DataDao;
import com.jsss.echarts.entity.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class DataService {

    @Autowired
    DataDao dataDao;


    public HashMap<String,Object> searchMap(){
        HashMap<String,Object> map=new HashMap<>();
        List<Data> dataList = search();
        List<Integer> inWaterList = new ArrayList<>();
        List<Integer> outWaterList = new ArrayList<>();
        List<Date> dateList = new ArrayList<>();

        for(Data data : dataList){
            inWaterList.add(data.getInWater());
            outWaterList.add(data.getOutWater());
            dateList.add(data.getDate());
        }

        map.put("inWaterList",inWaterList);
        map.put("outWaterList",outWaterList);
        map.put("dateList",dateList);

        return map;
    }

    public List<Data> search() {
        return dataDao.list();
    }

}
